//
//  MILFeedBackViewController.m
//  MicrowaveInteractionLight
//
//  Created by maple on 2016/12/15.
//  Copyright © 2016年 maple. All rights reserved.
//

#import "MILFeedBackViewController.h"
#import "FeedBackApi.h"
#import "FIDPlaceholderTextView.h"

@interface MILFeedBackViewController ()
@property (weak, nonatomic) IBOutlet FIDPlaceholderTextView *myTextView;
@property (weak, nonatomic) IBOutlet UITextField *myTextField;
//是否喜欢该产品
@property(nonatomic,copy)NSString *likeOwerProductString;
//是否喜欢该app设计
@property(nonatomic,copy)NSString *likeOwerAPPDesignerString;

@end

@implementation MILFeedBackViewController
#pragma mark -- UI
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



- (void)refreshBaseControlValue
{
    [self setNavigationBarTitle:@"意见反馈"];
    self.navigationBar.backgroundColor = [UIColor blackColor];
    [self setLeftButtonImage:[UIImage imageNamed:@"back_icon"]];
    
}

#pragma mark -- 按钮点击
//喜欢产品
- (IBAction)feedBackBtnClickAction:(UIButton *)btn {
    btn.selected = !btn.selected;
    if (btn.selected)
    {
        switch (btn.tag)
        {
            case 1:
            {
                self.likeOwerProductString = @"喜欢";
                UIButton *myBtn = [self.view viewWithTag:2];
                myBtn.selected = NO;
                UIButton *myBtn1 = [self.view viewWithTag:3];
                myBtn1.selected = NO;
            }
                break;
            case 2:
            {
                self.likeOwerProductString = @"还行";
                UIButton *myBtn = [self.view viewWithTag:1];
                myBtn.selected = NO;
                UIButton *myBtn1 = [self.view viewWithTag:3];
                myBtn1.selected = NO;
            }
                break;
            case 3:
            {
                self.likeOwerProductString = @"不喜欢";
                UIButton *myBtn = [self.view viewWithTag:1];
                myBtn.selected = NO;
                UIButton *myBtn1 = [self.view viewWithTag:2];
                myBtn1.selected = NO;
            }
                break;
                
            default:
                break;
        }
    }
    
    
}

//喜欢app设计
- (IBAction)feedBackLikeAPPClickAction:(UIButton *)btn {
    btn.selected = !btn.selected;
    if (btn.selected)
    {
        switch (btn.tag)
        {
            case 4:
            {
                self.likeOwerAPPDesignerString = @"喜欢";
                UIButton *myBtn = [self.view viewWithTag:5];
                myBtn.selected = NO;
                UIButton *myBtn1 = [self.view viewWithTag:6];
                myBtn1.selected = NO;
            }
                break;
            case 5:
            {
                self.likeOwerAPPDesignerString = @"还行";
                UIButton *myBtn = [self.view viewWithTag:4];
                myBtn.selected = NO;
                UIButton *myBtn1 = [self.view viewWithTag:6];
                myBtn1.selected = NO;
            }
                break;
            case 6:
            {
                self.likeOwerAPPDesignerString = @"不喜欢";
                UIButton *myBtn = [self.view viewWithTag:5];
                myBtn.selected = NO;
                UIButton *myBtn1 = [self.view viewWithTag:4];
                myBtn1.selected = NO;
            }
                break;
                
            default:
                break;
        }
    }
}


//提交
- (IBAction)commitFeedBackAction:(UIButton *)sender {
   
    if (![self.myTextField.text isMobileNumber]) {
        [SVProgressHUD showErrorWithStatus:@"联系方式不正确！"];
        return;
    }
    if ([self.myTextView.text isEqualToString:@""] || [self.myTextView.text isEqualToString:@"请告诉我们您遇到的问题或想反馈的意见"])
    {
        [SVProgressHUD showErrorWithStatus:@"反馈意见不能为空！"];
        return;
    }
    
    
    NSString *feedback = [self.myTextView.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];

    FeedBackApi *api = [[FeedBackApi alloc]initWith:@{@"content":feedback,@"type_id":TYPEID,@"contact_way":self.myTextField.text}];
    
    [api startWithCompletionAnimation:YES andBlockWithSuccess:^(__kindof YTKBaseRequest * _Nonnull request) {
        NSDictionary * myDic = [request responseJSONObject];
        NSLog(@"my Dic == %@ ",myDic);
        if ([myDic[@"errcode"] intValue] == 0) {
            [SVProgressHUD showSuccessWithStatus:@"反馈成功"];
            [self.navigationController popViewControllerAnimated:YES];
            
        }else{
            [SVProgressHUD showErrorWithStatus:myDic[@"errmsg"]];
        }
    } backfailure:^(__kindof YTKBaseRequest * _Nonnull request) {
        [SVProgressHUD showErrorWithStatus:@"请求失败"];

    } requestFailure:^(__kindof YTKBaseRequest * _Nonnull request) {
        [SVProgressHUD showErrorWithStatus:@"请求失败"];

    }];

}

#pragma mark -- UITextViewDelegate
//- (BOOL)textViewShouldBeginEditing:(UITextView *)textView
//{
//    if ([self.myTextView.text isEqualToString:@"请告诉我们您遇到的问题或想反馈的意见"])
//    {
//        self.myTextView.text = @"";
//    }
//    return YES;
//}

@end
